package com.bawei.db.util

import android.content.Context
import androidx.room.Room
import com.bawei.db.database.AppDataBase

/**
 * 对外提供统一数据库封装
 */
object RoomUtil {

    private const val dataBaseName = "part.db"
    private lateinit var dataBase: AppDataBase


    /**
     * 初始化数据
     */
    fun initRoomDataBase(ctx: Context){
        dataBase = Room.databaseBuilder(ctx, AppDataBase::class.java, dataBaseName).build()
    }

    /**
     * 获取数据库
     */
    fun getDataBase(): AppDataBase{
        if (dataBase == null){
           throw RuntimeException("数据库还没有初始化！！！")
        }
        return dataBase
    }
}